<template>
	<view class="beijingse" v-if="pageShow">
		<u-modal :show="show" cancelColor="#555" confirmColor="#ff9341" :showCancelButton="true" :title="title"
			@cancel="show=false" @confirm="confirm"></u-modal>
		<view class="mainpadding">
			<view class="dingwei flexcenter margin_top" @click="uploadImg(1,avatar,avatar_text)">
				<image  class="touxiang" :src="avatar_text!=''?avatar_text:'@/static/image/system/weidenglu.png'" mode=""></image>
				<image class="xianj" src="../static/image/system/xj.png" mode=""></image>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top1 flexbetween">
			<view class="sanshier fonweight">昵称</view>
			<input type="text" placeholder="请输入" style="text-align: right;" class="hei_text main_size bold" v-model="nickname" @blur="submit">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">会员编号</view>
			<input type="text" placeholder="请输入" disabled="" style="text-align: right;" class="hei_text main_size bold" v-model="idno">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">手机号</view>
			<input type="text" placeholder="请输入" disabled="" style="text-align: right;" class="hei_text main_size bold" v-model="mobile">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="jumper('/pages_mypage/xiugaidlmm?mobile=',mobile)">
			<view class="sanshier fonweight">修改登录密码</view>
			<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="jumper('/pages_mypage/xiugaizfmm?mobile=',mobile)">
			<view class="sanshier fonweight">修改支付密码</view>
			<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="jumper('/pages_mypage/bangdingyhk','')">
			<view class="sanshier fonweight">修改银行卡</view>
			<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
		</view>
		<!--  -->
		<view class="gudingdb ffffff mainpadding" @click="show = true">
			<view class="bigbtn">退出登录</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				avatar:"",
				avatar_text:"",
				nickname:"",
				mobile:"",
				pageShow:false,
				show: false,
				idno:"",
				title: '确定要退出当前账户么？',
			}
		},
		onShow() {
			this.init()
		},
		methods: {
				submit(){
					httpRequest.request('/api/user/profile', 'GET', {
						nickname:this.nickname,
						avatar:this.avatar
					}, false, false, true).then(res => {
						
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
				},
				init() {
					httpRequest.request('/api/user/index', 'GET', {}, false, false, true).then(res => {
						this.avatar = res.data.avatar
						this.avatar_text = res.data.avatar_text
						this.nickname = res.data.nickname
						this.idno = res.data.idno
						this.mobile = res.data.mobile
						this.pageShow = true
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
				},
				uploadImg(value, upImgs,upImgs_text) {
					let _this = this;
					uni.showActionSheet({
						itemList: ['相机', '相册'],
						success: function(res) {
							// 选择相机走0
							if (res.tapIndex == 0) {
								httpRequest.chooseImage(1, ['camera']).then(res => {
									for (var i = 0; i < res.length; i++) {
										_this.uploadImageService(res[i], upImgs,upImgs_text)
									}
								}).catch(err => {});
							}
							// 选择相册走1
							if (res.tapIndex == 1) {
								httpRequest.chooseImage(1, ['album']).then(res => {
									for (var i = 0; i < res.length; i++) {
										_this.uploadImageService(res[i], upImgs,upImgs_text)
									}
								}).catch(err => {});
							}
						},
						fail: function(res) {}
					});
				},
				uploadImageService(url, upImg,upImgs_text) {
					let _this = this;
					httpRequest.uploadFile('/api/common/upload', url).then(res => {
						let image_item = res.fullurl;
						this.avatar = res.url;
						this.avatar_text = image_item
						this.submit()
					}).catch(err => {});
				},
			
			jumper(url,val) {
				uni.navigateTo({
					url: url+val
				})
			},
			confirm() {
				this.show = false;
				// 将存储的数据改为空达到退出登录的效果
				uni.removeStorageSync('token');
				uni.removeStorageSync('user_id');
				httpRequest.toast("退出登录成功")
				setTimeout(() => {
					uni.navigateBack(1)
				}, 1000)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xianj {
		width: 46.13rpx;
		height: 46.13rpx;
		position: absolute;
		bottom: 0;
		right: 282rpx;
	}

	.touxiang {
		width: 182rpx;
		height: 182rpx;
		border-radius: 50%;
	}
</style>